﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Xml.Linq;
using SES.CMS.DO;
using SES.CMS.BL;

namespace SES.CMS
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            Application["online"] = 0;
        }

        protected void Session_Start(object sender, EventArgs e)
        {
            string ip = Request.ServerVariables["REMOTE_ADDR"].Trim();
            DateTime moment = DateTime.Now;

            CounterDO counterDO = new CounterDO();
            counterDO.IP = ip;
            counterDO.Date = moment;

            CounterBL counterDL = new CounterBL();
            counterDL.Insert(counterDO);
            //   Application.Lock();
            Application["online"] = Convert.ToInt32(Application["online"]) + 1;
            //   Application.UnLock();
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {
            Application.Lock();
            Application["online"] = Convert.ToInt32(Application["online"]) - 1;
            Application.UnLock();
        }

        protected void Application_End(object sender, EventArgs e)
        {
        }
    }
}